package com.dmx.fw.web.struts2.interceptor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.dmx.fw.constant.ViewConstant;

import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class BaseInterceptor implements Interceptor {
	public static final String ERROR_RESULT = "error";

	public String intercept(ActionInvocation arg0) throws Exception {
		// TODO Auto-generated method stub
		return arg0.invoke();
	}

	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	public void init() {
		// TODO Auto-generated method stub
		
	}
	
    /**
     * 保存错误信息
     * @param session
     * @param errorMsg
     */
    protected void setErrorInfo(Map session,String errorMsg){
    	List errorMsgList = (List)session.get(ViewConstant.GLOBAL_ERROR_INFO_KEY);
    	if (errorMsgList == null){
    		errorMsgList = new ArrayList();    		
    	}
    	errorMsgList.add(errorMsg);
    	if (session!=null){
    		 session.put(ViewConstant.GLOBAL_ERROR_INFO_KEY, errorMsgList);
    	}else{
    		 HttpServletRequest req = ServletActionContext.getRequest();
    		 req.setAttribute(ViewConstant.GLOBAL_ERROR_INFO_KEY, errorMsgList);
      }
    	
    }
}
